package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.AudioSearchResultPresenter
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.view.AudioSearchResultView
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.bean.AudioVideoBrowsingRecordBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.home_page.fragment.AudioSearchResultFragment
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class AudioSearchResultPresenterImp(var audioSearchResultView: AudioSearchResultView? = null): AudioSearchResultPresenter {
    /**
     * 获取管理音频数据列表
     */
    override fun getAudioSearchResultDataList(audioSearchResultFragment: AudioSearchResultFragment, classid: Int, key: String, curpage: Int) {
        audioSearchResultFragment.showLoadingDialog(audioSearchResultFragment.activity!! as CommonBaseActivity,"正在获取云课程列表数据...")
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getAudioListData(classid = classid,Key = key,curpage = curpage),audioSearchResultFragment,object:
            RxJavaCallBack<AudioVideoBrowsingRecordBean>(){
            override fun onSuccess(t: AudioVideoBrowsingRecordBean?) {
                audioSearchResultFragment.dismissLoadingDialog()
                audioSearchResultView?.audioFrequencyListDataGetSuccess(t)
            }

            override fun onRequestError(t: AudioVideoBrowsingRecordBean?) {
                super.onRequestError(t)
                audioSearchResultFragment.dismissLoadingDialog()
                audioSearchResultView?.audioFrequencyListDataGetFailed()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                audioSearchResultFragment.dismissLoadingDialog()
                audioSearchResultView?.audioFrequencyListDataGetFailed()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        audioSearchResultView = baseView as? AudioSearchResultView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        audioSearchResultView = null
    }
}